package com.zhentao.controller;

import com.zhentao.config.Result;
import com.zhentao.pojo.TbWrongQuestions;
import com.zhentao.service.TbWrongQuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

// 错题记录
@RestController
@RequestMapping("wrong")
public class TbWrongQuestionControllerLx {

    @Autowired
    private TbWrongQuestionsService tbWrongQuestionsService;

    //根据id查询详细内容
    @RequestMapping("getById")
    public Result<TbWrongQuestions> getById(Integer id){
        TbWrongQuestions tbWrongQuestions1 = tbWrongQuestionsService.getById(id);
        return tbWrongQuestions1 != null ? Result.success(tbWrongQuestions1) : Result.error("查询失败");
    }

    // 根据用户id查询用户错题
    @RequestMapping("getUserId")
    public Result<List<TbWrongQuestions>> getUserId(@RequestBody TbWrongQuestions tbWrongQuestions) {
        List<TbWrongQuestions> tbWrongQuestions1 = tbWrongQuestionsService.queryWrongQuestionsByUserId(tbWrongQuestions);
        return tbWrongQuestions1 != null ? Result.success(tbWrongQuestions1) : Result.error("查询失败");

    }

    // 添加用户错题
    @RequestMapping("addUserWrong")
    public Result<String> addUserWrong(@RequestBody TbWrongQuestions tbWrongQuestions){
        boolean save = tbWrongQuestionsService.save(tbWrongQuestions);
        return save ? Result.success("添加成功") : Result.error("添加失败");
    }





}
